package com.common.base.widget

import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
import com.common.base.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：7/3/2023
 *
 * 描述：
 *
 * 修订历史：
 *
 */
class MaxHeightScrollView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) :
    ScrollView(context, attrs, defStyleAttr) {
    private val maxHeight: Int
    private val defaultHeight = 250

    init {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView)
        maxHeight = typedArray.getDimensionPixelSize(
            R.styleable.MaxHeightScrollView_mhsv_max_height,
            defaultHeight
        )
        typedArray.recycle()
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(
            widthMeasureSpec,
            MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST)
        )
    }
}